import React from "react";
import { Link, Routes, Route, useLocation } from "react-router-dom";

const Home = () => {
  return <div>这是home页面</div>;
};
const About = () => {
  return <div>这是about页面</div>;
};
const Detail = () => {
  // useLocation可以获取query的参数
  const location = useLocation();
  const searchParams = new URLSearchParams(location.search);
  console.log(searchParams.get("id"));

  return <div>这是Detail页面</div>;
};

const App = () => {
  return (
    <>
      <h2>react-query传参</h2>

      <ul>
        <li>
          <Link to="/home">首页</Link>
        </li>
        <li>
          <Link to="/about">关于页</Link>
        </li>
        <li>
          <Link to="/detail?id=123&name=zhangsan">详情页1</Link>
        </li>
        <li>
          <Link to="/detail?id=456&name=lisi">详情页2</Link>
        </li>
      </ul>

      <Routes>
        {/* query传参在Route不用做任何处理 */}
        <Route path="/home" element={<Home />}></Route>
        <Route path="/about" element={<About />}></Route>
        <Route path="/detail" element={<Detail />}></Route>
      </Routes>
    </>
  );
};

export default App;
